﻿namespace com.oakwoodsys.Extensions.SharePointExtensions
{
    using System;

    using Microsoft.SharePoint.Administration;

    public static class SPFarmExtensions
    {
        #region Methods

        public static bool DoesFeatureExist( this SPFarm spFarm, Guid featureId )
        {
            if ( featureId == null || featureId.Equals( Guid.Empty ) )
                return false;
            return spFarm.GetFeatureDefinition( featureId ) == null ? false : true;
        }

        public static SPFeatureDefinition GetFeatureDefinition( this SPFarm spFarm, Guid featureId )
        {
            if ( featureId == null || featureId.Equals( Guid.Empty ) )
                return null;
            foreach ( SPFeatureDefinition o in spFarm.FeatureDefinitions )
                if ( o.Id.Equals( featureId ) )
                    return o;
            return null;
        }

        #endregion Methods
    }
}